# closed_lexicon.rb

require 'fastercsv'

class ClosedLexica
  attr_reader :lexica, :pos

  def initialize(row)
    @lexica = row[0]
    @pos = [row[1]]
    @pos << row[2] if row[0]
  end
end

class ClosedLexicon
  attr_reader :size
  
  def initialize(csvfile)
    @dictionary = {}
    @size = 0
    FasterCSV.foreach(csvfile) do |row|
      clx = ClosedLexica.new(row)
      self[row[0]] = clx
    end
  end
  
  def [](key)
    @dictionary[key]
  end
  
  def []=(key, value)
    @dictionary[key] ||= []
    @dictionary[key] << value
    @size += 1
  end
  
  def each_pair(&p)
    @dictionary.each_pair(&p)
  end
end

